import { nursingWorkersListApi } from '@/api/pcs/pcsNursingWorkers'
import { defaultPageSize } from '@/utils/antdHelper'
import modelExtend from '@/utils/dvaUtil/modelExtend'

export const namespace = 'pcsNursingWorkers'

const initialState = {
  searchParams: {},
  pagination: {
    current: 1,
    pageSize: defaultPageSize,
    total: 0,
  },
  pageList: [],
  topCount: {
    count: 0, // 护工数量
    freeCount: 0, // 待岗数量
    personalCompanionCount: 0, // 专人陪护数量
    teamCompanionCount: 0, // 团队陪护数量
    inHospitalCount: 0, // 医院数量
    inHomeCount: 0, // 居家数量
  },
}

export default modelExtend({
  namespace,
  state: initialState,
  matchedActions: toAction => {
    toAction('getPageList')
  },
  effects: {
    *getPageList({ payload }, { call, update, select }) {
      const { searchParams, pagination } = yield select(state => state[namespace])
      const params = {
        ...searchParams,
        ...pagination,
        ...payload,
      }

      const { data } = yield call(nursingWorkersListApi, params)
      const { content, current, pageSize, total, ...other } = data
      yield update({ pageList: content, pagination: { current, pageSize, total }, topCount: other })
    },
  },
})
